<!-- TabControl -->
<template>
  <div class="tab-control">
    <div class="tab-control-item" v-for="(item,index) in titles" :key="index" :class="{active :index ===curentIndex}"
      @click="itemClick(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'TabControl',
    data() {
      return {
        curentIndex: 0
      }
    },
    props: {
      titles: {
        type: Array,
        default () {
          return []
        }
      }
    },
    //生命周期 - 创建完成（访问当前this实例）
    created() {

    },
    //生命周期 - 挂载完成（访问DOM元素）
    mounted() {

    },
    methods: {
      itemClick(index) {
        console.log(index)
        this.curentIndex = index;
        this.$emit("tabClick",index);
      }
    },
  }

</script>
<style scoped>
  /* @import url(); 引入css类 */
  .tab-control {
    display: flex;
    text-align: center;
    font-size: 14px;
    height: 40px;
    line-height: 40px;
    background-color: #fff;
  }

  .tab-control-item {
    flex: 1;
  }

  .active span {
    color: var(--color-high-text);
    border-bottom: 2px solid var(--color-high-text);
    padding: 5px;
  }

  .tab-control {
    position: sticky;
    top: 44px;
    z-index:10
  }

</style>
